package com.RLFZ.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.RLFZ.entity.Role;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (role)数据Mapper
 *
 * @author zh
 * @since 2022-08-25 17:16:58
 * @description 
*/
@Mapper
@Repository
public interface RoleMapper extends BaseMapper<Role> {
    @Select("select mid from role_menu where rid=#{roleId}")
    List<Integer> queryMidByRid(Integer roleId);

    // 1.分配菜单栏之前删除所有的rid数据
    @Delete("delete from role_menu where rid = #{rid}")
    void deleteRoleByRid(Integer rid);

    // 2.保存分配 角色 与 菜单 的关系
    @Insert("insert into role_menu(rid,mid) values (#{rid},#{mid})")
    void saveRoleMenu(@Param("rid") Integer rid, @Param("mid") Integer mid);

    // id查询所有的角色
    @Select("select rid from user_role where uid=#{id}")
    List<Integer> queryUserRoleById(Integer id);

    // 1. 先删除之前的用户与角色关系
    @Delete("delete from user_role where uid = #{uid}")
    void deleteRoleUserByUid(Integer uid);

    //2. 保存分配的用户与角色之间的关系
    @Insert("insert into user_role(uid,rid) values(#{uid},#{rid})")
    void saveUserRole(@Param("uid") Integer uid, @Param("rid") Integer rid);
    @Select("select mid from role_menu where rid=#{rid}")
    List<Integer> queryAllPermissionByRid(Integer rid);
}
